<template>
  <div class="app-container">
    <Ht-search-form
      v-show="showSearch"
      :dictMap="dictMapAsync"
      :queryParams="queryParams"
      :outputQueryParams="queryParams"
      :formOptions="formOptions"
      :advOptions="[]"
      :defaultEventKey="defaultEventKey"
      :labelWidth="160"
    ></Ht-search-form>


    <ht-table
      ref="dataTable"
      :multi-select="false"
      :showSerialNumber="false"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :tableBindColumns="tableBindColumns"
      :opButtonList="opButtonList"
      :reqConfig="regConfig"
      :defaultEventKey="defaultEventKey"
    >
      <template v-slot:operate>
        <el-table-column label="操作" align="left" width="50" fixed="right">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '明细',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <!-- 添加或修改弹出框 -->
    <el-dialog :title="title" center :visible.sync="open" width="1024px" append-to-body :close-on-click-modal="false" v-if="open">
      <el-form ref="detailForm" :model="detailForm" :rules="rules" label-width="160px">
      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="原交易流水号/原批次流水号" prop="oriId">
            <el-input v-model="detailForm.oriId" :disabled="true" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="原报文标识号" prop="oriPkgid">
            <el-input v-model="detailForm.oriPkgid" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>


      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="原系统编号" prop="oriSysCode">
            <el-input v-model="detailForm.oriSysCode" :disabled="true"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="原报文类型" prop="oriMsgType">
            <el-input v-model="detailForm.oriMsgType" :disabled="true"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="原工作日期" prop="oriWorkdate">
            <el-date-picker v-model="detailForm.oriWorkdate" style="width: 100%;" type="date" value-format="yyyyMMdd" :disabled="true"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="原发起参与机构" prop="oriDirectSender">
            <el-input v-model="detailForm.oriDirectSender" :disabled="true"/>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="原付款清算行行名称" prop="oriDirectSenderBrname">
            <el-input v-model="detailForm.oriDirectSenderBrname" :disabled="true"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="原接收参与机构" prop="oriPayeeStBrno">
            <el-input v-model="detailForm.oriPayeeStBrno" :disabled="true"/>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="原收款清算行行名称" prop="oriPayeeStBrname">
            <el-input v-model="detailForm.oriPayeeStBrname" :disabled="true"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="中心状态" prop="procStatus">
            <el-select style="width: 100%;" v-model="detailForm.procStatus" placeholder="中心状态" :disabled="true">
              <el-option
                v-for="dict in dictMap.PROCESSSTATUS"
                :key="dict.value"
                :label="`${dict.value}-${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>


      <el-row type="flex">
        <el-col :span="24">
          <el-form-item label="附言" prop="addInfo">
            <el-input type="textarea" v-model="detailForm.addInfo" maxlength="105" show-word-limit/>
          </el-form-item>
        </el-col>
      </el-row>
      </el-form>

      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" @click="save" v-loading.fullscreen.lock="loading">提 交</el-button>
        <el-button type="primary" @click="refresh">重 置</el-button>
        <el-button type="primary" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { listPageMixin } from "@/libs/listPageMixin";

import HtAmountInput from "@/views/components/HtAmountInput";

import BankBranchDialog from "@/views/components/BankBranchDialog";
import BaseDataDialog from "@/views/components/BasedataDialog";
import {
  realTimePaymentRevokeEntryDetail,
  realTimePaymentRevokeEntryQuery,
  realTimePaymentRevokeEntrySave,
} from "@/api/cnaps/beps/365";

export default {
  name: "RealTimePaymentRevokeEntry",
  mixins: [listPageMixin],
  components: { BaseDataDialog, BankBranchDialog, HtAmountInput },
  data() {
    return {
      // 查询参数
      queryParams: {
        idSeqno: undefined,
        startworkdate: undefined,
        endworkdate: undefined,
      },
      loading: false,
      // 搜索
      defaultEventKey: "defaultEventKey",
      formOptions: [],
      //
      searchFormDictList: ["PROCESSSTATUS"],
      // 列信息
      regConfig: realTimePaymentRevokeEntryQuery,

      tableBindColumns: [
        { prop: 'oriId',  label: '原交易流水号/原批次流水号',width:200},
        { prop: 'oriSysCode',  label: '原系统编号'},
        { prop: 'oriWorkdate',  label: '原工作日期', type:'date'},
        { prop: 'oriMsgType',  label: '原报文类型'},
        { prop: 'oriPayerStBrno',  label: '原发起参与机构'},
        { prop: 'oriPayeeStBrno',  label: '原接收参与机构'},
        { prop: 'procStatus',  label: '中心状态', dictCode:'PROCESSSTATUS' },
      ],


      dictMapAsync: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      detailForm: {
        addInfo:undefined,

      },
      totalRecord: 0,
      totalPage: 0,
      needCount: 0,
      rules: {

      },
    };
  },

  mounted() {
    const formOptions = [
      // 普通搜索

      {
        type: "input",
        prop: "idSeqno",
        defaultAttr: {
          size: "small",
          label: "原交易流水号/原批次流水号",
          placeholder: "请输入原交易流水号/原批次流水号",
        },
      },

      {
        type: "dates",
        nameObj: {
          startTimeName: "startworkdate",
          endTimeName: "endworkdate",
        },
        defaultAttr: {
          size: "small",
          label: "工作日期",
          placeholder: ["请输入工作日期开始", "请输入工作结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },
    ];
    this.formOptions = formOptions;
    this.dictMapAsync = this.getDictMap();
  },
  methods: {
    /***
     * 按钮操作汇总
     */
    /***
     * 按钮操作汇总
     */
    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
      }
    },

    //点击重置按钮
    refresh() {
      this.resetForm("detailForm");
    },

    // 关闭按钮
    cancel() {
      this.open = false;
    },

    /** 详情按钮操作 */
    handleDetail(row) {
      this.title = "实时缴款撤销申请报文录入明细";
      realTimePaymentRevokeEntryDetail(row).then((response) => {
        this.detailForm = response.result;
        this.$set(this.detailForm,'addInfo','');
        this.open = true;
      });
    },
    //点击提交按钮
    save: function () {
      this.$refs["detailForm"].validate((valid) => {
        if (valid) {
          realTimePaymentRevokeEntrySave(this.detailForm)
            .then((response) => {
              this.loading = true;
              this.msgSuccess("提交成功");
              this.open = false;
              this.loading = false;
              this.$nextTick(() => {
                this.$refs.dataTable.doQuery(true);
              });
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },

  },
};
</script>
